package com.ruoyi.project.dict.cizudb.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.dict.cizudb.domain.CizuDb;
import com.ruoyi.project.dict.cizudb.service.ICizuDbService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 词组(汉典)Controller
 * 
 * @author shixiangwen
 * @date 2020-06-11
 */
@Controller
@RequestMapping("/dict/cizudb")
public class CizuDbController extends BaseController
{
    private String prefix = "dict/cizudb";

    @Autowired
    private ICizuDbService cizuDbService;

    @RequiresPermissions("dict:cizudb:view")
    @GetMapping()
    public String cizudb()
    {
        return prefix + "/cizudb";
    }

    /**
     * 查询词组(汉典)列表
     */
    @RequiresPermissions("dict:cizudb:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CizuDb cizuDb)
    {
        startPage();
        List<CizuDb> list = cizuDbService.selectCizuDbList(cizuDb);
        return getDataTable(list);
    }

    /**
     * 导出词组(汉典)列表
     */
    @RequiresPermissions("dict:cizudb:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CizuDb cizuDb)
    {
        List<CizuDb> list = cizuDbService.selectCizuDbList(cizuDb);
        ExcelUtil<CizuDb> util = new ExcelUtil<CizuDb>(CizuDb.class);
        return util.exportExcel(list, "cizudb");
    }

    /**
     * 新增词组(汉典)
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存词组(汉典)
     */
    @RequiresPermissions("dict:cizudb:add")
    @Log(title = "词组(汉典)", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CizuDb cizuDb)
    {
        return toAjax(cizuDbService.insertCizuDb(cizuDb));
    }

    /**
     * 修改词组(汉典)
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CizuDb cizuDb = cizuDbService.selectCizuDbById(id);
        mmap.put("cizuDb", cizuDb);
        return prefix + "/edit";
    }

    /**
     * 修改保存词组(汉典)
     */
    @RequiresPermissions("dict:cizudb:edit")
    @Log(title = "词组(汉典)", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CizuDb cizuDb)
    {
        return toAjax(cizuDbService.updateCizuDb(cizuDb));
    }

    /**
     * 删除词组(汉典)
     */
    @RequiresPermissions("dict:cizudb:remove")
    @Log(title = "词组(汉典)", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cizuDbService.deleteCizuDbByIds(ids));
    }
}
